package com.besttone.search.sql;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class NativeDBHelper extends SQLiteOpenHelper {
	public static final String AREA_CODE = "AREA_CODE";
	public static final int AREA_CODE_INDEX = 9;
	public static final String BUSINESS_FLAG = "BUSINESS_FLAG";
	public static final int BUSINESS_FLAG_INDEX = 12;
	public static final int DATABASE_VERSION = 1;
	public static final String ENG_NAME = "ENG_NAME";
	public static final int ENG_NAME_INDEX = 7;
	public static final String FIRST_PY = "FIRST_PY";
	public static final int FIRST_PY_INDEX = 6;
	public static final String ID = "ID";
	public static final int ID_INDEX = 0;
	public static final String IS_FREQUENT = "IS_FREQUENT";
	public static final int IS_FREQUENT_INDEX = 10;
	public static final String NAME = "NAME";
	public static final int NAME_INDEX = 4;
	public static final String PARENT_REGION = "PARENT_REGION";
	public static final int PARENT_REGION_INDEX = 2;
	public static final String REGION_CODE = "REGION_CODE";
	public static final int REGION_CODE_INDEX = 1;
	public static final String SHORT_NAME = "SHORT_NAME";
	public static final int SHORT_NAME_INDEX = 5;
	public static final String SORT_VALUE = "SORT_VALUE";
	public static final int SORT_VALUE_INDEX = 11;
	public static final String TEL_LENGTH = "TEL_LENGTH";
	public static final int TEL_LENGTH_INDEX = 8;
	public static final String TYPE = "TYPE";
	public static final String TYPE_CITY = "2";
	public static final String TYPE_DISTRICT = "3";
	public static final int TYPE_INDEX = 3;
	public static final String TYPE_PROVINCE = "1";
	private static NativeDBHelper sInstance;
	private final String[] mColumns;

	private NativeDBHelper(Context paramContext) {
		super(paramContext, "native_database.db", null, 1);
		String[] arrayOfString = new String[8];
		arrayOfString[0] = "ID";
		arrayOfString[1] = "REGION_CODE";
		arrayOfString[2] = "PARENT_REGION";
		arrayOfString[3] = "TYPE";
		arrayOfString[4] = "SHORT_NAME";
		arrayOfString[5] = "FIRST_PY";
		arrayOfString[6] = "AREA_CODE";
		arrayOfString[7] = "BUSINESS_FLAG";
		this.mColumns = arrayOfString;
	}

	public static NativeDBHelper getInstance(Context paramContext) {
		if (sInstance == null)
			sInstance = new NativeDBHelper(paramContext);
		return sInstance;
	}

	public void onCreate(SQLiteDatabase paramSQLiteDatabase) {
	}

	public void onUpgrade(SQLiteDatabase paramSQLiteDatabase, int paramInt1,
			int paramInt2) {
	}

	public Cursor select(String[] paramArrayOfString1, String paramString,
			String[] paramArrayOfString2) {
		return getReadableDatabase().query("PUB_LOCATION", paramArrayOfString1,
				paramString, paramArrayOfString2, null, null, null);
	}

	public Cursor selectAllCity() {
		String[] arrayOfString = new String[1];
		arrayOfString[0] = "2";
		return select(this.mColumns, "TYPE=?", arrayOfString);
	}

	public Cursor selectCodeByName(String paramString) {
		String[] arrayOfString = new String[1];
		arrayOfString[0] = paramString;
		return select(this.mColumns, "SHORT_NAME=?", arrayOfString);
	}

	public Cursor selectDistrict(String paramString) {
		String[] arrayOfString = new String[2];
		arrayOfString[0] = "3";
		arrayOfString[1] = paramString;
		return select(this.mColumns, "TYPE=? AND PARENT_REGION like ?",
				arrayOfString);
	}

	public Cursor selectNameByCode(String paramString) {
		String[] arrayOfString = new String[1];
		arrayOfString[0] = paramString;
		return select(this.mColumns, "REGION_CODE=?", arrayOfString);
	}
}